home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0063_Sprite Talk.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  3KB  |  112 lines

  1. {
  2. >Try converting it to use pointers instead of accessing the array with
  3. >indexes, and use a pointer to video memory for direct plots
  4. >instead of using the putPixel routine. Also it's quicker to
  5. >check against 0 for the background than to check against
  6. >255.
  7.  
  8. > I found a copy of "The Visible Computer: 8088" in my bookshelves and
  9. > tried rewriting my assembly routines.  Here's what I finally got:
  10.  
  11. > procedure MaskPut(x,y: word; p: pointer); assembler;
  12. > var
  13. > XX,YY: byte;
  14. > asm
  15. > LES SI,p
  16. > MOV [XX],0
  17. > MOV [YY],0
  18. > MOV CX,256
  19. > XOR DX,DX
  20. > CLD
  21. > @Loopit:SEGES LODSB
  22. > MOV DL,AL
  23. > PUSH ES
  24. > PUSH SI
  25. > CMP DL,255
  26. > JZ @Done
  27. > MOV AX,0A000h
  28. > MOV ES,AX
  29. > MOV AX,320
  30. > MOV BX,[Y]
  31. > ADD BL,[YY]
  32. > PUSH DX
  33. > MUL BX
  34. > POP DX
  35. > MOV BX,[X]
  36. > ADD BL,[XX]
  37. > ADD AX,BX
  38. > MOV SI,AX
  39. > MOV ES:[SI],DL
  40. > @Done:  INC [XX]
  41. > CMP [XX],16
  42. > JNZ @Okay
  43. > MOV [XX],0
  44. > INC [YY]
  45. > @Okay:  POP SI
  46. > POP ES
  47. > LOOP @Loopit
  48. > end;
  49.  
  50. > It works fine.  I didn't notice much of a difference in speed though.
  51. > I tested it and I can plot about 1103 sprites/second in ASM and 828
  52. > sprites/sec. with my original TP code.  Please keep in mind I'm not
  53. > much of an assembly programmer. Can anyone help me optimize this code
  54. > (into 286 would be good too). Thanx for your help!
  55.  
  56. I'll try. I notice you're using memory variables for loop counters in that
  57. code. Also seem to be reloading the segment registers each time through the
  58. loop, and general sundry pushes, pops, and such which are unnecesary. I don't
  59. have time to rewrite your code from scratch today but I'll post my transparent
  60. bitmap routine for Mode 13 for you to use/learn from. K?
  61.  
  62. this is untested, I was fixing it up after I found it my optimization gets
  63. better over time, and it's been a while since I've worked on this Mode 13h
  64. stuff.
  65. }
  66.  
  67. {$G+}
  68.  
  69. procedure drawSprite(x, y : integer; w, h : byte; sprite : pointer); assembler;
  70. asm
  71.  push ds
  72.  lds si,[sprite]
  73.  mov ax,$A000
  74.  mov es,ax
  75.  cld
  76.  mov ax,[y]     {y * 320}
  77.  shl ax,6
  78.  mov di,ax
  79.  shl ax,2
  80.  add di,ax
  81.  add ax,[x]     {+ x}
  82.  mov bh,[h]
  83.  mov cx,320     {dif between rows}
  84.  sub cl,[w]
  85.  sbb ch,0
  86. @L:
  87.  mov bl,[w]
  88. @L2:
  89.  lodsb
  90.  or al,al       {test for 0. For 255 you'd use inc al here instead}
  91.                 {heck dx and ah are free, you could store the
  92.                   comparison value in one of those}
  93.  jnz @S
  94.                 {for 255 you'd also need a dec al here}
  95.  mov [es:di],al
  96. @S:
  97.  inc di
  98.  dec bl
  99.  jnz @L2
  100.  add di,cx
  101.  dec bh
  102.  jnz @L
  103.  pop ds
  104.  end;
  105.  
  106. {
  107. And I'll bet you notice a difference in speed with this puppy. 8)
  108.  
  109. If you could guarantee that the width would be an even number you could
  110. optimize it to use word moves, otherwise it wouldn't be worth it.
  111. }
  112.